package com.bcu.cn.onlineexamsystem.studentmanage.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Map;

@Mapper
public interface StudentHomeMapper {
    
    /**
     * 根据用户ID查询用户真实姓名
     */
    @Select("SELECT real_name FROM users WHERE user_id = #{userId}")
    String getRealNameByUserId(@Param("userId") String userId);
    
    /**
     * 查询学生累计参加的考试数量（status = 2 表示已提交）
     */
    @Select("SELECT COUNT(*) FROM student_exams WHERE student_id = #{studentId} AND status = 2")
    Integer getTotalExamsCount(@Param("studentId") String studentId);
    
    /**
     * 查询学生待参加的考试数量（status = 0 表示未考）
     */
    @Select("SELECT COUNT(*) FROM student_exams WHERE student_id = #{studentId} AND status = 0")
    Integer getUpcomingExamsCount(@Param("studentId") String studentId);
    
    /**
     * 查询学生最近一次考试信息
     */
    @Select("SELECT e.exam_name, c.course_name, se.total_score as student_score, " +
            "e.total_score as exam_total_score, se.submit_time " +
            "FROM student_exams se " +
            "JOIN exams e ON se.exam_id = e.exam_id " +
            "JOIN courses c ON e.course_id = c.course_id " +
            "WHERE se.student_id = #{studentId} AND se.status = 2 " +
            "ORDER BY se.submit_time DESC " +
            "LIMIT 1")
    Map<String, Object> getLastExamInfo(@Param("studentId") String studentId);
    
    /**
     * 查询最近一次题库更新信息
     */
    @Select("SELECT c.course_name, q.type, q.create_time " +
            "FROM questions q " +
            "JOIN courses c ON q.course_id = c.course_id " +
            "ORDER BY q.create_time DESC " +
            "LIMIT 1")
    Map<String, Object> getLatestQuestionInfo();
} 